package com.hongxun.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.entity.APBaseEntity;
import com.hongxun.modules.bss.service.APBaseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.api.entity.BEntryCriteriaEntity;
import com.hongxun.modules.api.service.BEntryCriteriaService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 准入条件
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-07-27 13:51:28
 */
@RestController
@RequestMapping("/api/bentrycriteria")
public class BEntryCriteriaController {
	@Autowired
	private BEntryCriteriaService bEntryCriteriaService;
	@Autowired
	private APBaseService aPBaseService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("aguid")!=null&&!query.get("aguid").toString().equals(""))
		{
			wheres+=" and  b_guid = '" + query.get("aguid").toString()+"' ";
		}
		if(query.get("eCType")!=null&&!query.get("eCType").toString().equals(""))
		{
			wheres+=" and  e_c_type = '" + query.get("eCType").toString()+"' ";
		}
		if(query.get("eCSaml")!=null&&!query.get("eCSaml").toString().equals(""))
		{
			wheres+=" and  e_c_saml = '" + query.get("eCSaml").toString()+"' ";
		}

        query.put("filterSql",wheres+" ");
		List<BEntryCriteriaEntity> bEntryCriteriaList = bEntryCriteriaService.queryList(query);
		int total = bEntryCriteriaService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(bEntryCriteriaList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	@RequestMapping("/listselect")
	public R listselect(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		APBaseEntity sPBaseEntity = aPBaseService.queryObject(query.get("pguid").toString());
       if(sPBaseEntity.getSGuid()!=null&&!sPBaseEntity.getSGuid().equals(""))
	   {
		   wheres += " and  FIND_IN_SET(b_guid,'" + sPBaseEntity.getSGuid() + "')";

	   }
		wheres+=" and  e_c_type = '" + sPBaseEntity.getPBType()+"' ";

		if(query.get("eCSaml")!=null&&!query.get("eCSaml").toString().equals(""))
		{
			wheres+=" and  e_c_saml = '" + query.get("eCSaml").toString()+"' ";
		}

		query.put("filterSql",wheres+" ");
		List<BEntryCriteriaEntity> bEntryCriteriaList = bEntryCriteriaService.queryList(query);
		int total = bEntryCriteriaService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(bEntryCriteriaList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		BEntryCriteriaEntity bEntryCriteria = bEntryCriteriaService.queryObject(guid);
		
		return R.ok().put("bEntryCriteria", bEntryCriteria);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody BEntryCriteriaEntity bEntryCriteria){
		bEntryCriteriaService.save(bEntryCriteria);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody BEntryCriteriaEntity bEntryCriteria){
		bEntryCriteriaService.update(bEntryCriteria);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		bEntryCriteriaService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
